#include "loginwidget.h"
#include "ui_loginwidget.h"
#include "faceidentify.h"
#include <QMessageBox>

loginWidget::loginWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::loginWidget)
{
    ui->setupUi(this);

    //设置登录界面
    setWindowTitle("登录");
    //设置账号、密码最长长度,10, 10
    ui->accountEdit->setMaxLength(10);
    ui->passwordEdit->setMaxLength(10);
    //设置密码回显模式
    ui->passwordEdit->setEchoMode(QLineEdit::Password);
    faceUi = new faceIdentify;

    //信号关联到槽
    connect(faceUi, SIGNAL(showLogin()), this, SLOT(show()));

}

loginWidget::~loginWidget()
{
    delete ui;
}


void loginWidget::on_loginButton_clicked()
{
    //获取账号内容
    QString account = ui->accountEdit->text();
    if(account.isEmpty()) {
//        QMessageBox::warning(this, "警告，账号不得为空");
        return;
    }
    QString password = ui->passwordEdit->text();
    if(password.isEmpty()) {
//        QMessageBox::warning(this, "警告， 密码不得为空");
        return;
    }
    //验证账号密码是否正确
    if(account != "admin" || password != "123") {
//        QMessageBox::warning(this, "警告， 账号或密码错误");
        return;
    }
    //清除用户名和密码
    ui->accountEdit->clear();
    ui->passwordEdit->clear();


    //跳转到人脸打卡界面
    this->close();//先关闭当前窗口
    //显示人脸打卡考勤界面
    faceUi->show();
}


void loginWidget::on_exitButton_clicked()
{
    // 退出
    exit(0);
}

